#!/bin/sh

readonly KEY="$1"

orient() {
	while read file; do
		mogrify -auto-orient "$file"
	done
}

rotate() {
	degree="$1"
	while read file; do
		case "$(file -b -i "$file")" in
		image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "$file" "$file" ;;
		*) mogrify -rotate "$degree" "$file" ;;
		esac
	done
}

case "$KEY" in
"C-c")      tr '\n' ' ' | xsel -i ;;
"C-e")      while read file; do urxvt -bg "#444" -fg "#eee" -sl 0 -title "$file" -e sh -c "exiv2 pr -q -pa '$file' | less" & done ;;
"C-g")      tr '\n' '\0' | xargs -0 gimp & ;;
"C-o")      orient ;;
"C-comma")  rotate 270 ;;
"C-period") rotate  90 ;;
"C-slash")  rotate 180 ;;
"C-d")      while read file; do trash "$file"; done ;;
esac
